<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 递枕头 -->
    <script>
      var passThePillow = function (n, time) {
        /**
         * 如果n=3，则生成[1,2,3,2]为循环数组
         * 对time进行取余，看余数在那里
         */
        let arr = []
        for (let i = 1; i <= n; i++) {
          arr.push(i)
        }
        for (let i = n - 1; i > 1; i--) {
          arr.push(i)
        }
        let flag = time % arr.length
        return arr[flag]
      }
      console.log(passThePillow(4, 5))
    </script>
  </body>
</html>
